/*
* @Author: HuangXiongHui
* @Date:   2017-12-09 21:12:38
* @Last Modified by:   HuangXiongHui
* @Last Modified time: 2017-12-12 15:40:35
*/
$(document).ready(function(){ 
  //读取 localStage 本地存储，填充用户名密码,如果自动登录有值直接跳转； 
  //相反，跳转到本页面,等待登陆处理 
  var storage = window.localStorage; 
    var getusername = storage["username"]; 
    var getPwd = storage["password"]; 
    var getisstroepwd = storage["isstorePwd"]; 
    var getisautologin = storage["isautologin"]; 
    if("yes" == getisstroepwd) 
    { 
        if("yes" == getisautologin) 
        { 
            if(( ("" != getusername) ||(null != getusername)) && (("" != getPwd) ||(null != getPwd))) 
            { 
                //lacoste  已经保存 登陆信息 直接登陆 
                // alert('正在自动登录');
                $("#username").val(getusername);
                $("#password").val(getPwd); 
               // window.location="";  
               //加载时显示：正在自动登录
                $.ajax({
     url : '../servlet/LoginServlet?choose=login',
     data : {
      username :  getusername,
      password : getPwd
     },
     dataType : 'json',
     success : function(data) {
      if (data.msg == "") {
       alert("账号信息异常，请核实后重新登录");
      } else {
      //登录成功后保存session，如果选择了记住密码，再保存到本地
       //window.location.href ='../index/index.jsp';
      }
     },
     error : function() {
     
     }
       });
            } 
        } 
        else 
        {    
                $("#username").val(getusername); 
                $("#password").val(getPwd); 
                document.getElementById("remember").checked = true; 
        } 
    } 
 }); 
function login(){
  var userusername=$("#username").val(); 
    var userPassWord=$("#password").val(); 
 
    var storage = window.localStorage; 
    //记住密码 
    if(document.getElementById("remember").checked) 
    { 
        //存储到loaclStage   
 
        storage["username"] = userusername; 
        storage["password"] =  userPassWord; 
        storage["isstorePwd"] =  "yes"; 
    } 
    else 
    { 
        storage["username"] = userusername; 
        storage["isstorePwd"] =  "no"; 
    } 
 
    //下次自动登录 
    if(document.getElementById("isAutoLoginId").checked) 
    { 
        //存储到loaclStage   
        storage["username"] = userusername; 
        storage["password"] =  userPassWord; 
        storage["isstorePwd"] =  "yes"; 
        storage["isautologin"] =  "yes"; 
    } 
    else 
    { 
        storage["username"] = userusername; 
        storage["isautologin"] =  "no"; 
    }
     $.ajax({
   url : '../servlet/LoginServlet?choose=login',
   data : {
    username : userusername,
    password : userPassWord
   },
   dataType : 'json',
   success : function(data) {
    if (data.msg == "") {
     alert("用户名或密码错误");
    } else {
    //登录成功后保存session，如果选择了记住密码，再保存到本地
     window.location.href ='../index/index.jsp';
    }
   },
   error : function() {

   }
    });
    alert("登录成功");
}